<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    * {
      margin: 0;
      padding: 0;
    }
    body, html {
      height: 100%;
    }
    .content {
      position: relative;
      height: 100%;
      background-color: #000;
      overflow: hidden;
    }
    .yudi {
      position: absolute;
      opacity: 0;
      animation: drops 3s cubic-bezier(0.32, 0.7, 1, 1) infinite;
      /* 落雨 */
      /* width: 8px;
      height: 12px;
      background-color: #ccc;
      clip-path: ellipse(10% 30% at 50% 50%); */
      /* 红包 */
      width: 50px;
      height: 90px;
      background: url('../images/hongbao.png') no-repeat center;
      background-size: 100%;
      transform: translate3d(110px, 0, 0) skew(-20deg, 26deg);
    }
    @keyframes drops {
      0% {
        opacity: 0;
      }
      20% {
        opacity: 1;
      }
      90% {
        opacity: 1;
      }
      100% {
        opacity: 0;
        transform: translate3d(10px, 100vh, -10px) skew(-40deg, 26deg);
      }
    }
  </style>
</head>
<body>
  <div class="content">
    <div class="yudi"></div>
  </div>
  <script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
  <script>
    let $content = $('.content')
    let initNumber = 0;

    for(let i=0;i<30;i++) {
      let lefts = Math.floor(Math.random() * 5 + 2);
      // let lefts = 3.3;
      let delay = Math.floor(Math.random() * 50 + 2);
      initNumber += lefts
      let $div = $('<div/>').addClass('yudi').css({
        'left': `${initNumber}%`,
        "top": -`${lefts}%`,
        "animation-delay": `${delay/10}s`
      })
      $content.append($div)
    }
  </script>
</body>
</html>